Back to Article
sparse_coordinate_spaces.ipynb
Download Notebook
In [4]:

import numpy as np
from itertools import product

roi =  list('aaaa') + list('bbbb')
c = list('0123') + list('1234')
print(f"roi: {roi}")
print(f"c:   {c}")
roi: ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b']
c:   ['0', '1', '2', '3', '1', '2', '3', '4']

Here we have two rois 'a' and 'b' that share channels ['1', '2', '3'] but have a unique one each ('0'/'4'). We create our dataset coordinates by taking the unique values of each component dimension (which is the same as taking the set union of the individual coordinates).

In [14]:
dataset_roi = np.unique(roi).tolist()
dataset_c = np.unique(c).tolist()

print(f"roi: {dataset_roi}")
print(f"c:   {dataset_c}")
roi: ['a', 'b']
c:   ['0', '1', '2', '3', '4']

Now we can look at the component space that our aggregated coordinates create, by taking their Cartesian product:

In [17]:
# cartesian product & returning the result in the same format as above
space_roi, space_c = list(zip(*product(dataset_roi, dataset_c)))

print("before:")
print(f"roi: {list(roi)}")
print(f"c:   {list(c)}")
print()
print("after:")
print(f"roi: {list(space_roi)}")
print(f"c:   {list(space_c)}")
before:
roi: ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b']
c:   ['0', '1', '2', '3', '1', '2', '3', '4']

after:
roi: ['a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'b']
c:   ['0', '1', '2', '3', '4', '0', '1', '2', '3', '4']

As we can see, the fact that we had heterogeneous channel coordinates resulted in an overly large component space when constructed from the aggregated dataset level base coordinates. On the positive side, since the space is too large, we can still uniquely identify each dataset component. But we need to be careful because if we were to do measurements in channel '0' for both ROIs we might end up with null values, depending on how we organize our feature tables. Since we now know about the issue we can come up with a simple measure of sparsity as the percentage empty spots after doing the exact operation we just did.

In [20]:
print(f"sparsity: {len(roi) / len(space_roi)}")
sparsity: 0.8